package edu.nus.mtech.sem1.ca.cust.complaint;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import edu.nus.mtech.sem1.ca.service.Service;
import edu.nus.mtech.sem1.ca.utils.TelephonyUtils;

/**
 * Holds all the information about a single complaint. The Customer class will encapsulate a
 * collection of complaints
 *
 */
public class Complaint {
	
	//NRIC;ACCOUNT_NO;SERVICE;COMPLAINT_NO;COMPLAINT;STATUS
	private String nric;
	private String accountNo;
	private Service service;
	private String complaintNo;
	private String complaintDesc;
	private ComplaintStatus status;
	private Date complaintDate;
	private SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");

	public Complaint(){
		nric= "";
		accountNo="";
		service=Service.DVOICE;
		complaintNo="C-";
		complaintDesc="";
		complaintDate=new Date();
		status=ComplaintStatus.OPEN;
	}

	@Override
	public boolean equals(Object complaintObj) {
		boolean allResult=false;
		
		if (complaintObj!=null && complaintObj instanceof Complaint){
			Complaint incomingComplaint=(Complaint)complaintObj;
			
			if (incomingComplaint.getNric().equals(nric)){
				allResult=true;
			}
			if (incomingComplaint.getAccountNo().equals(accountNo)){
				allResult=allResult && true;
			}
			if (incomingComplaint.getService().equals(service)){
				allResult=allResult && true;
			}
			if (incomingComplaint.getComplaintNo().equals(complaintNo)){
				allResult=allResult && true;
			}
			if (incomingComplaint.getComplaintDesc().equals(complaintDesc)){
				allResult=allResult && true;
			}
			if (incomingComplaint.getStatus().equals(status)){
				allResult=allResult && true;
			}
			if (incomingComplaint.getComplaintDate().equals(complaintDate)){
				allResult=allResult && true;
			}
			
		}
		return allResult;
	}
	
	@Override
	public int hashCode() {
		//Had to override the hashcode method because we have overridden the equals method.
		// Just multiplying with a good primary number to avoid false duplicates
		int hashCode=(TelephonyUtils.getHashCode(nric)*73)+TelephonyUtils.getHashCode(accountNo)+TelephonyUtils.getHashCode(service)+TelephonyUtils.getHashCode(complaintNo)+TelephonyUtils.getHashCode(complaintDesc)+TelephonyUtils.getHashCode(status)+TelephonyUtils.getHashCode(complaintDate);
		return hashCode;
		
	}

	@Override
	public String toString() {
		return(nric+"::"+accountNo+"::"+service+"::"+complaintNo+"::"+complaintDesc+"::"+complaintDate+"::"+status);
	}
	
	public String getNric() {
		return nric;
	}

	public void setNric(String nric) {
		this.nric = nric;
	}

	public String getAccountNo() {
		return accountNo;
	}

	public void setAccountNo(String accountNo) {
		this.accountNo = accountNo;
	}

	public Service getService() {
		return service;
	}

	public void setService(Service service) {
		this.service = service;
	}

	public String getComplaintNo() {
		return complaintNo;
	}

	public void setComplaintNo(String complaintNo) {
		this.complaintNo = complaintNo;
	}

	public String getComplaintDesc() {
		return complaintDesc;
	}

	public void setComplaintDesc(String complaintDesc) {
		this.complaintDesc = complaintDesc;
	}

	public ComplaintStatus getStatus() {
		return status;
	}

	public void setStatus(ComplaintStatus status) {
		this.status = status;
	}

	public Date getComplaintDate() {
		return complaintDate;
	}

	public void setComplaintDate(Date complaintDate) {
		this.complaintDate = complaintDate;
	}
	
	public void setComplaintDate(String complaintDate) throws ParseException {
		this.complaintDate=formatter.parse(complaintDate);
	}
}
